{
LANG : PASCAL
PROB : range
}

program RANGE;
const
  fi = 'range.in';
  fo = 'range.out';
  max = 250;
  oo = 10000;
var
  d, h, s, l, o : array[0..max] of longint;
  n : integer;

procedure init;
begin
  fillchar(s, sizeof(s), 0);
  fillchar(d, sizeof(d), 0);
end;

function min(x, y : integer) : integer;
begin
  if x > y then min := y
  else min := x;
end;

function min3(x, y, z : integer) : integer;
begin
  if y < x then x := y;
  if z < x then x := z;
  min3 := x;
end;

procedure process;
var
  i, j, k, side : integer;
  c : char;
begin
  for i := 1 to n do
  begin
    for j := 1 to n do
    begin
      read(c);
      o[j] := ord(c) - 48;
    end;
    readln;

    for j := 1 to n do
      if o[j] = 0 then h[j] := 0
      else inc(h[j]);

    for j := 1 to n do
      if o[j] = 0 then l[j] := 0
      else l[j] := l[j-1]+1;

    for j := n downto 1 do
      if o[j] = 1 then
      begin
        side := min3(h[j], l[j], d[j-1]+1);
        for k := 2 to side do inc(s[k]);
        d[j] := side;
      end
      else d[j] := 0;
  end;
end;

procedure out;
var
  i : integer;
begin
  for i := 2 to n do
    if s[i] > 0 then writeln(i, ' ', s[i]);
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  readln(n);
  init;
  process;
  out;
  close(output);
  close(input);
end.